*** NOTES: 
*** Hand coded data set is in Data/manual_encodings/all_manual_encodings.xlsx
*** The basic information on all patents in the google data base is in Data/all_patents_basicinfo.dta
***

set matsize 5000


import excel using "Data/manual_encodings/all_manual_encodings.xlsx", first clear
save "Data/all_manual_encodings.dta", replace

use "Data/all_patents_basicinfo.dta"
merge 1:1 patnum using "Data/all_manual_encodings.dta"

keep if _merge == 3
drop _merge
tab iyear

tab iyear if nclassgoogle1 == 623

// Generates estimates in Tables D.2, D.5

*** Generate variables describe the "pre patent boom" period, the "patent 
*** boom" period, and the "post patent boom" period for the Civil War and WWI.
gen period = .
replace period = 0 if iyear >= 1855 & iyear <= 1861
replace period = 0 if iyear >= 1910 & iyear <= 1915
replace period = 1 if iyear >= 1862 & iyear <= 1866
replace period = 1 if iyear >= 1916 & iyear <= 1922
replace period = 2 if iyear >= 1867 & iyear <= 1880
replace period = 2 if iyear >= 1923 & iyear <= 1940

*** Generate a numeric variable for the individual war episodes
gen warepisode = .
replace warepisode = 1 if iyear >= 1840 & iyear <= 1890
replace warepisode = 2 if iyear >= 1890 & iyear <= 1940

gen patentcount = 1
gen prosthetics = nclassgoogle1 == 623

gen usertraits = (comfort + appearance)/2  
gen production = (adjustability + simplicity + cost)/3 

capture eststo clear
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials ///
	if warepisode == 1 & prosthetics == 1, columns(statistics) statistics(mean)
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 1 & prosthetics == 0, columns(statistics) statistics(mean)
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 2 & prosthetics == 1, columns(statistics) statistics(mean)
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 2 & prosthetics == 0, columns(statistics) statistics(mean)

// Table D.2:
esttab using "Tables/TrainingSetSummaryStatsAll.tex", replace main(mean) aux(sd) label nomtitle nolegend nonotes compress


capture eststo clear
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 1 & period == 0 & prosthetics == 1, columns(statistics) statistics(mean)
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 1 & period == 1 & prosthetics == 1, columns(statistics) statistics(mean)
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 1 & period == 0 & prosthetics == 0, columns(statistics) statistics(mean)
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 1 & period == 1 & prosthetics == 0, columns(statistics) statistics(mean)

esttab using "Tables/TrainingSetSummaryStatsDD.tex", replace main(mean) aux(sd) label nomtitle nolegend nonotes compress

capture eststo clear
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 2 & period == 0 & prosthetics == 1, columns(statistics) statistics(mean)
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 2 & period == 1 & prosthetics == 1, columns(statistics) statistics(mean)
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 2 & period == 0 & prosthetics == 0, columns(statistics) statistics(mean)
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 2 & period == 1 & prosthetics == 0, columns(statistics) statistics(mean)

esttab using "Tables/TrainingSetSummaryStatsDD.tex", append main(mean) aux(sd) label nomtitle nolegend nonotes compress




drop if period == .
collapse (sum) patentcount (mean) production usertraits cost simplicity adjustability comfort appearance durability materials  , by(prosthetics period warepisode)
reshape wide patentcount production usertraits cost simplicity adjustability comfort appearance durability materials  , i(prosthetics warepisode) j(period) 
reshape wide patentcount* production* usertraits* cost* simplicity* adjustability* comfort* appearance* durability* materials*, i(warepisode) j(prosthetics) 

foreach trait in production usertraits cost simplicity adjustability comfort appearance durability materials  {
	gen `trait'changeprosth = `trait'11 - `trait'01
	gen `trait'changeother = `trait'10 - `trait'00
	gen `trait'diffdiff = `trait'changeprosth - `trait'changeother
}

reshape long patentcount production usertraits cost simplicity adjustability comfort appearance durability materials, i(warepisode)  j(event) string

foreach trait in production usertraits cost simplicity adjustability comfort appearance durability materials   {
	label var `trait' "`trait'"
}

capture eststo clear
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 1 & event == "01", columns(statistics) statistics(mean)
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 1 & event == "11" , columns(statistics) statistics(mean)
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 1 & event == "00", columns(statistics) statistics(mean)
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 1 & event == "10", columns(statistics) statistics(mean)
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 1 & event == "changeprosth", columns(statistics) statistics(mean)
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 1 & event == "changeother", columns(statistics) statistics(mean)
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 1 & event == "diffdiff", columns(statistics) statistics(mean)

esttab using "Tables/TrainingSetCollSummaryStatsDD.tex", replace main(mean) aux(sd) label nomtitle nolegend nonotes compress

capture eststo clear
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 2 & event == "01", columns(statistics) statistics(mean)
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 2 & event == "11" , columns(statistics) statistics(mean)
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 2 & event == "00", columns(statistics) statistics(mean)
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 2 & event == "10", columns(statistics) statistics(mean)
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 2 & event == "changeprosth", columns(statistics) statistics(mean)
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 2 & event == "changeother", columns(statistics) statistics(mean)
eststo: estpost tabstat production usertraits cost simplicity adjustability comfort appearance durability materials  ///
	if warepisode == 2 & event == "diffdiff", columns(statistics) statistics(mean)

// Generates the final Table D.5:
esttab using "Tables/TrainingSetCollSummaryStatsDD.tex", append main(mean) aux(sd) label nomtitle nolegend nonotes compress






